package com.msos.dao.customerDao;


import com.msos.model.customer.Customer;
import com.msos.model.manager.Manager;
import com.msos.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 弟中弟：小邦
 */
public class CustomerDao {

    QueryRunner queryRunner = new QueryRunner(DBUtils.getDs());

    //根据手机号查询用户信息
    public Object getCustomerByPhone(String phone,String role) throws SQLException {
        if (Integer.parseInt(role) == 1){
            return queryRunner.query("select * from customer where phone=?",new BeanHandler<>(Customer.class),phone);
        }else {
            return queryRunner.query("select * from manager where name=?",new BeanHandler<>(Manager.class),phone);
        }
    }

    public Integer updatePasswordByCustomer(String password,String phone) throws SQLException {
        return queryRunner.update("update customer set password=? where phone=?",password,phone);
    }
}
